﻿using System.Collections.Generic;

namespace System.Xml.Serialization
{
    public static class XmlSerializerExtentions
    {
        private static readonly object sf_LockObject = new object();

        private static Dictionary<Type, XmlSerializer> sf_XmlSerializersPool;

        [Diagnostics.DebuggerStepThrough]
        public static XmlSerializer GetSerializer(Type type)
        {
            XmlSerializer lv_Result;
            lock(sf_LockObject)
            {
                if(sf_XmlSerializersPool == null)
                    sf_XmlSerializersPool = new Dictionary<Type, XmlSerializer>();

                if(!sf_XmlSerializersPool.TryGetValue(type, out lv_Result))
                    sf_XmlSerializersPool.Add(type, lv_Result = new XmlSerializer(type));
            }
            return lv_Result;
        }
    }
}
